/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */

package com.ykht.proj.activity.controller.c;

import com.ykht.proj.activity.entity.VActivity;
import com.ykht.proj.activity.entity.VCard;
import com.ykht.proj.activity.mapper.VCardMapper;
import com.ykht.proj.activity.mq.producer.MsgProducer;
import com.ykht.proj.activity.service.VActivityService;
import com.ykht.proj.activity.service.VCardService;
import com.ykht.proj.activity.vo.*;
import com.ykht.proj.common.core.util.R;
import com.ykht.proj.common.security.annotation.Inner;
import com.ykht.proj.comsrv.constant.ComConstant;
import com.ykht.proj.comsrv.vo.SubscribeMsgCouponExpire;
import com.ykht.proj.coupon.vo.BaseLonLat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.swing.text.DateFormatter;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;


/**
 * 卡表
 *
 * @author csg
 * @date 2021-05-21 14:21:47
 */
@RestController
@RequestMapping("c/vcard" )
@Api(value = "vcard", tags = "c端卡相关")
@Slf4j
public class CVCardController {

	@Resource
    private VCardService vCardService;
	@Resource
    private VActivityService vActivityService;
	@Resource
    private MsgProducer msgProducer;




    @ApiOperation(value = "卡列表")
    @GetMapping("/list" )
    public R<List<Card4C>> list(Card4CReq req,BaseLonLat lonLat) {
    	log.info("->c端卡列表{},{}",req,lonLat);
		try {
			List<Card4C> list = vCardService.cardList(req,lonLat);
			return R.ok(list);
		} catch (Exception e) {
			e.printStackTrace();
			return R.failed("获取列表失败");
		}
	}
    @ApiOperation(value = "c端分销卡列表")
    @GetMapping("/fxList" )
    public R<List<Card4C>> fxList(Card4CReq req,BaseLonLat lonLat) {
    	log.info("->c端分销卡列表{},{}",req,lonLat);
		try {
			req.setFxFlag(1);//设置成参与
			List<Card4C> list = vCardService.cardList(req,lonLat);
			return R.ok(list);
		} catch (Exception e) {
			e.printStackTrace();
			return R.failed("获取列表失败");
		}
	}
    @ApiOperation(value = "卡列表")
    @GetMapping("/test" )
	@Inner(false)
    public void list() {
		try {

			/*SubscribeMsgCouponExpire couponExpire = new SubscribeMsgCouponExpire();
			couponExpire.setType(ComConstant.SUBSCRIBE_MSG_COUPON_EXPIRE);
			couponExpire.setContent("活动内容");
			couponExpire.setCouponId(1l);
			couponExpire.setCouponName("优惠券");
			couponExpire.setEndTime(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
			couponExpire.setPersonId(822l);
			couponExpire.setOpenId("o7xw-5NxoLCQgYCb3eLZkyKSzBU4");
			couponExpire.setPrice(BigDecimal.valueOf(1));*/

			vActivityService.sendMq(new VActivity().selectById(2));
		} catch (Exception e) {
		}
	}

    @ApiOperation(value = "活动列表")
    @GetMapping("/list4Activity" )
    public R<ActivityInfo> list4Activity(Card4CReq req,BaseLonLat lonLat) {
    	log.info("->c端卡列表{},{}",req,lonLat);
		try {
			ActivityInfo activityInfo = vCardService.getActivityInfo(req,lonLat);
			return R.ok(activityInfo);
		} catch (Exception e) {
			e.printStackTrace();
			return R.failed("获取列表失败");
		}
	}

    @ApiOperation(value = "卡详情")
    @GetMapping("/{id}" )
    public R<VCardInfo> getById(@PathVariable("id" ) Long id,BaseLonLat lonLat) {
		log.info("->c端卡详情{},{}",id,lonLat);
        return R.ok(vCardService.getCardInfo(id,lonLat));
    }


}
